package com.jt.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;

/**
 * @ClassName ResourceConfig
 * @Description TODO
 * @Author Jiyao
 * @DATE 2021-11-29 15:15
 * @Version 1.0
 **/

@Configuration
//启动资源服务器默认配置
@EnableResourceServer
//访问资源服务器中的相关方法（@PreAuthorize注解描述的方法）时启动权限检查
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class ResourceConfig extends ResourceServerConfigurerAdapter {
    @Override
    public void configure(HttpSecurity http) throws Exception {
        //super.configure(http);
        //1、关闭跨域攻击
        http.csrf().disable();
        //2、放行相关请求
        http.authorizeRequests()
                //路径以/resource开头进行拦截
                .antMatchers("/resource/**")
                //其他放行
                .authenticated()
                .anyRequest().permitAll();
    }
}
